package com.rovicorp.qa.performance;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;

public class MyServlet extends HttpServlet implements Servlet {

	public MyServlet() {}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();

		Mongo m = new Mongo( "tul1cstapp05", 27017);

		DB db = m.getDB("test");

		DBCollection coll = db.getCollection("test");

        //String queryParams = request.getParameter("q");
		//db.test.group({cond:{},key:{"rs_time_avg":1},initial:{},$reduce:{},finalize:{}})
		BasicDBObject key = new BasicDBObject("fqe",1).append("rs_time_avg",1).append("buildId",1);
		BasicDBObject empty = new BasicDBObject();

		DBObject grp = coll.group(key,empty,empty,"function(){}","function(){}");

		out.print(grp);

        //request.setAttribute("results", myDoc);
        //request.getRequestDispatcher("/index.jsp").forward(request,response);

	}
}
